import { useState } from "react"

interface ProduceModelDataType {
  workingOrder: any
  totalOrders: any[]
  showTotalOrders: boolean
  isOperateMode: boolean // 工单是否在操作模式下,比如编辑模式和搜索模式,如果是这个模式下,收到后台的更新数据,忽略
  totalBoardImageData: string | null
  totalBoardErrorInfo: string
  totalboardErrorModalVisible: boolean
  sizeCheckModalVisible: boolean
  sizeCheckImageData: string | null
  inputSize: number[]
  boardSize: number[]
  boardCalcError: number[]
  scanHintInfo: string // 添加扫描提示信息字段

  handLabelModalVisible: boolean
  handLabelImageData: string | null
  handLabelSize: number[]
  labelBoardSizeMm: number[]
  cutLineModalVisible: boolean
  cutLineImageData: string | null
  calcResInfo: string
  isReturned: boolean

  handSingleBoxSrc: string | null
  handSingleBoxVisible: boolean
  labelSingleBoxSizeMm: number[]
  labelSingleBoxSizePix: number[]

  deviceLockModalVisible: boolean

  produceAmountData: any[]
  produceDayAmountData: any[]

  scanModalVisible: boolean
  alarmRecords: any[]
  searchOrders: any[]
  orderChoosed: any
  offlineModalVisible: boolean

  firstCutLineRes: string | null
  firstCutLineSize: number[]
  firstCalError: number[]
  cutBoardSizeFirst: number[]
  catchCenter01FirstCut: string
  catchCenter02FirstCut: string

  notFirstCutLineRes: string | null
  notFirstCutLineSize: number[]
  notFirstImageSize: number[]
  notFirstCalError: number[]
  catchCenter01: string
  catchCenter02: string
  calcSize: number[]
  cimMessageModalVisible: boolean
  cimMessageType: string
  cimMessage: string
  showTimeLeft: number
}

export default function produceModel() {
  const initData: ProduceModelDataType = {
    workingOrder: {},
    totalOrders: [],
    showTotalOrders: true,
    isOperateMode: false,
    totalBoardImageData: null,
    totalBoardErrorInfo: "",
    totalboardErrorModalVisible: false,
    sizeCheckModalVisible: false,
    sizeCheckImageData: null,
    inputSize: [],
    boardSize: [],
    boardCalcError: [],
    scanHintInfo: "", // 初始化扫描提示信息
    handLabelModalVisible: false,
    handLabelImageData: null,
    handLabelSize: [],
    labelBoardSizeMm: [],
    cutLineModalVisible: false,
    cutLineImageData: null,
    calcResInfo: "",
    isReturned: false,
    handSingleBoxSrc: null,
    handSingleBoxVisible: false,
    labelSingleBoxSizeMm: [],
    labelSingleBoxSizePix: [],

    deviceLockModalVisible: false,
    produceAmountData: [],
    produceDayAmountData: [],
    scanModalVisible: false,
    alarmRecords: [],
    searchOrders: [],
    orderChoosed: null,
    offlineModalVisible: false,

    firstCutLineRes: null,
    firstCutLineSize: [], // 首件显示在前端显示的图像尺寸
    firstCalError: [],
    cutBoardSizeFirst: [],
    catchCenter01FirstCut: "(0,0,0)",
    catchCenter02FirstCut: "(0,0,0)",

    notFirstCutLineRes: null,
    notFirstImageSize: [],
    calcSize: [],
    notFirstCutLineSize: [],
    notFirstCalError: [],
    catchCenter01: "(0,0,0)",
    catchCenter02: "(0,0,0)",
    cimMessageModalVisible: false,
    cimMessageType: "",
    cimMessage: "",
    showTimeLeft: 0
  }

  const [produceData, setProduceData] = useState<ProduceModelDataType>(initData)

  const updateProduceData = (newData: Partial<ProduceModelDataType>) => {
    setProduceData((prevData) => ({ ...prevData, ...newData }))
  }

  return {
    ...produceData,
    updateProduceData
  }
}
